/*

WARNING: DO NOT USE WITH MORE THAN THE FOLLOWING PARTS:
	MSP430G2452
	32768 CRYSTAL
	SW1/SW2 & 1M Ohm Pullup resistors.
	3.3V Regulator***

*** Do not use the 3.3V regulator AND the programming Vcc simultaneoulsy.
There is no protection for this.

This is designed to test the 32.768Khz crystal. It will generate a signal
at approximately 64Hz on all of P1 outputs.

*/

#include <msp430.h>
#include "ui.h"

#define NOP __asm__ __volatile__("nop") 	//single cycle nop.
#define NOP2 __asm__ __volatile__("jmp $+0x02") 	//single cycle nop.
#define NOP5 __asm__ __volatile__("mov @R4,0(R4)") 	//single cycle nop.

void delay_ten_us(register unsigned int tens)
{
	tens--;
	while(tens--)
	{
		NOP5;
		NOP;
	}
	NOP2;
	NOP2;
}
int main()
{
	WDTCTL = WDTPW + WDTHOLD;
	
	P2DIR = 0x3F;
	P2OUT = 0x00;

	P1DIR = ~(BUTTON_SEL | BUTTON_ENT);
	P1OUT = 0x00;

	while(1)
	{
		if((P1IN & BUTTON_SEL) == 0)
		{
			P2OUT>>=1;
			P2OUT &= 0x3F;
			if(P2OUT == 0x00)
				P2OUT = 0x20;
			delay_ten_us(0);
		}
		else if((P1IN & BUTTON_ENT) == 0)
		{
			P2OUT<<=1;
			P2OUT &= 0x3F;
			if(P2OUT == 0)
			{
				P2OUT = 0x0001;
			}
			delay_ten_us(0);
		}
	}

	return 0;
}
